package oop.core.med;
import oop.core.entity.Avatar;
import oop.core.entity.MerchantNPC;
import oop.core.item.*;

public class TransactionMediator{

	private Avatar avatar;
	private MerchantNPC merchantNPC;
	
	public TransactionMediator(Avatar avatar){
		this.avatar = avatar;
		this.merchantNPC=null;
	}

	//.startTransaction and .clearTransaction added to deal with TransactionMediator
	//as a persistent mediator
	public void startTransaction(MerchantNPC theMerch){
		this.merchantNPC=theMerch;
	}
	
	public void clearTransaction(){
		this.merchantNPC=null;
	}

	
	public boolean buy(int i){
		if(merchantNPC==null){
			return false;
		}
		return avatar.buy(merchantNPC.buyItem(i));
	}
	
	public boolean sell(int i){
		if(merchantNPC==null){
			return false;
		}
		merchantNPC.sellItem(avatar.sell(i));
		return true;
	}

}